package com.byedu.util;

import java.io.IOException;
import java.lang.reflect.Type;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotWritableException;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.byedu.model.result.Result;

/**
 * Created by weidangwang on 2017/4/22.
 */
public class ResultConverter extends FastJsonHttpMessageConverter {

    @SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
    public void write(Object t, Type type, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        Result result = new Result();
        if (t instanceof Void) {
        } else {
            result.setData(t);
        }

        super.write(result, type, contentType, outputMessage);
    }
}
